home *** CD-ROM | disk | FTP | other *** search
/ Visual Cafe 3 / Visual Cafe 3.ISO / Vcafe / JFC.bin / BasicToolTipUI.java < prev    next >
Text File  |  1998-06-30  |  4KB  |  119 lines

  1. /*
  2.  * @(#)BasicToolTipUI.java    1.22 98/04/06
  3.  *
  4.  * Copyright (c) 1997 Sun Microsystems, Inc. All Rights Reserved.
  5.  *
  6.  * This software is the confidential and proprietary information of Sun
  7.  * Microsystems, Inc. ("Confidential Information").  You shall not
  8.  * disclose such Confidential Information and shall use it only in
  9.  * accordance with the terms of the license agreement you entered into
  10.  * with Sun.
  11.  *
  12.  * SUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF THE
  13.  * SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
  14.  * IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
  15.  * PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR ANY DAMAGES
  16.  * SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR DISTRIBUTING
  17.  * THIS SOFTWARE OR ITS DERIVATIVES.
  18.  *
  19.  */
  20.  
  21. package com.sun.java.swing.plaf.basic;
  22.  
  23. import java.awt.*;
  24. import com.sun.java.swing.*;
  25. import com.sun.java.swing.BorderFactory;
  26. import com.sun.java.swing.border.Border;
  27. import com.sun.java.swing.plaf.ToolTipUI;
  28. import com.sun.java.swing.plaf.ComponentUI;
  29. import com.sun.java.swing.plaf.UIResource;
  30. import java.io.Serializable;
  31.  
  32.  
  33. /**
  34.  * Standard tool tip L&F.
  35.  * <p>
  36.  * Warning: serialized objects of this class will not be compatible with
  37.  * future swing releases.  The current serialization support is appropriate
  38.  * for short term storage or RMI between Swing1.0 applications.  It will
  39.  * not be possible to load serialized Swing1.0 objects with future releases
  40.  * of Swing.  The JDK1.2 release of Swing will be the compatibility
  41.  * baseline for the serialized form of Swing objects.
  42.  *
  43.  * @version 1.22 04/06/98
  44.  * @author Dave Moore
  45.  */
  46. public class BasicToolTipUI extends ToolTipUI implements Serializable
  47. {
  48.     static BasicToolTipUI sharedInstance = new BasicToolTipUI();
  49.  
  50.     public static ComponentUI createUI(JComponent c) {
  51.         return sharedInstance;
  52.     }
  53.  
  54.     public BasicToolTipUI() {
  55.         super();
  56.     }
  57.  
  58.     public void installUI(JComponent c) {
  59.     installDefaults(c);
  60.     installListeners(c);
  61.     }
  62.  
  63.     public void uninstallUI(JComponent c) {
  64.     // REMIND: this is NOT getting called
  65.     uninstallDefaults(c);
  66.     uninstallListeners(c);
  67.     }
  68.  
  69.     protected void installDefaults(JComponent c){
  70.     LookAndFeel.installColorsAndFont(c, "ToolTip.background",
  71.                      "ToolTip.foreground",
  72.                      "ToolTip.font");
  73.         LookAndFeel.installBorder(c, "ToolTip.border");
  74.     }
  75.     
  76.     protected void uninstallDefaults(JComponent c){
  77.     LookAndFeel.uninstallBorder(c);
  78.     }
  79.  
  80.     protected void installListeners(JComponent c) {
  81.     }
  82.  
  83.     protected void uninstallListeners(JComponent c) {
  84.     }
  85.  
  86.     public void paint(Graphics g, JComponent c) {
  87.         Font font = c.getFont();
  88.         FontMetrics metrics = Toolkit.getDefaultToolkit().getFontMetrics(font);
  89.         Dimension size = c.getSize();
  90.  
  91.         g.setColor(c.getBackground());
  92.         g.fillRect(0, 0, size.width, size.height);
  93.         g.setColor(c.getForeground());
  94.         g.setFont(font);
  95.         g.drawString(((JToolTip)c).getTipText(), 3, 2 + metrics.getAscent());
  96.     }
  97.  
  98.     public Dimension getPreferredSize(JComponent c) {
  99.         Font font = c.getFont();
  100.         FontMetrics metrics = Toolkit.getDefaultToolkit().getFontMetrics(font);
  101.     // fix for bug 4094153
  102.     String tipText = ((JToolTip)c).getTipText();
  103.     if (tipText == null)
  104.       return new Dimension(6,metrics.getHeight() + 4);
  105.     else
  106.       return new Dimension(metrics.stringWidth(tipText) + 6,
  107.                    metrics.getHeight() + 4);
  108.     }
  109.  
  110.     public Dimension getMinimumSize(JComponent c) {
  111.         return getPreferredSize(c);
  112.     }
  113.  
  114.     public Dimension getMaximumSize(JComponent c) {
  115.         return getPreferredSize(c);
  116.     }
  117.  
  118. }
  119.